package com.lanou3g.code0512.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by dllo on 18/5/12.
 */
@WebServlet(name = "RequestServlet",urlPatterns ="/search" )
public class RequestServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      response.setContentType("text/html;charset=utf-8");
        //方法二:在获取参数之前 告诉tomcat参数是utf-8编码的
        //在get请求中 这种方式不行 ⬇️
        //request.setCharacterEncoding("utf-8");

        String keyword=request.getParameter("keyword");
//        byte[]bytes=keyword.getBytes("iso-8859-1");//方法一: 转换回原始二进制
//        keyword =new String(bytes,"utf-8");//将转成二进制数据用utf8编码转换成字符串

        response.getWriter().println("用户输入的是:"+keyword);
    }
}
